<?php
$this->Paginator->options(array('url' => array('ext' => false, '?' => $this->request->query)));
?>
<div class="section">
    <?php
    echo $this->element('toolbar');
    ?>
    <!-- Table -->
    <div class="table-wrapper">
        <?php echo $this->Form->create('Filter', array('url' => '/' . $this->request->url, 'type' => 'get')); ?>
        <div class="table-toolbar clearfix">
            <div class="input table-length">

            </div>
            <div class="table-filter">
                <?php
                echo __d('system', 'Block region for theme %s', $this->Form->input('limit', array(
                            'id' => 'filter-limit', 'options' => $_themes, 'div' => false, 'label' => false)));
                ?>
            </div>
        </div>



        <div id="table-options" style="display:none" class="table-options panel clearfix"></div>

        <?php echo $this->Form->end(); ?>
        <?php echo $this->Form->create('Paginate', array('id' => 'paginate', 'url' => $this->request->here(false), 'type' => 'post', 'inputDefaults' => array('label' => false))); ?>
        <div class="paginate-place">
            <?php if (!empty($_crumbs)): ?>
                <div class="table-breadcrumb table-toolbar clearfix">
                    <?php
                    $this->Html->addCrumb(__d('system', 'Users'), array(
                        'ext' => false,
                        '?' => array_diff_key($this->request->query, array('_parent_id' => ''))
                    ));
                    $_endcrumb = array_pop($_crumbs);
                    foreach ($_crumbs as $_crumb) {
                        $this->Html->addCrumb($_crumb['User'][$_modelMaps['User']], array(
                            'ext' => false,
                            '?' => array_merge($this->request->query, array('_parent_id' => $_crumb['User']['id']))));
                    }
                    $this->Html->addCrumb($this->Html->tag('a', $_endcrumb['User'][$_modelMaps['User']]));
                    echo $this->Html->getCrumbs();
                    ?>
                </div>
            <?php endif; ?>
            <div class="table-scroll">
                <div class="table-content">
                    <table>
                        <thead>
                            <tr>
                                <th>
                                    <span class="table-head table-select">
                                        <span class="ui-icon ui-icon-flag"></span>
                                        <input class="toggle" value="row-id" type="checkbox" title="<?php echo __d('system', 'Check all.'); ?>" />
                                    </span>
                                </th>
                                <?php if (isset($_displayFields['id'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('id', __d('system', 'Id')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['username'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('username', __d('system', 'Username')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['fullname'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('fullname', __d('system', 'Fullname')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['password'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('password', __d('system', 'Password')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['introduct'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('introduct', __d('system', 'Introduct')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['fulltext'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('fulltext', __d('system', 'Fulltext')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['gender'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('gender', __d('system', 'Gender')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['birthday'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('birthday', __d('system', 'Birthday')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['email'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('email', __d('system', 'Email')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['phone'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('phone', __d('system', 'Phone')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['enabled'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('enabled', __d('system', 'Enabled')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['role_id'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('role_id', __d('system', 'Role')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['created'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('created', __d('system', 'Created')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['updated'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('updated', __d('system', 'Updated')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['lft'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('lft', __d('system', 'Lft')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['rght'])): ?>
                                    <th>
                                        <span class="table-head">
                                            <?php echo $this->Paginator->sort('rght', __d('system', 'Rght')); ?>
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <?php if (isset($_translateMaps)): ?>
                                    <th>    
                                        <span class="table-head">
                                            <span class="ui-icon ui-icon-gear"></span>
                                            <?php echo __d('system', 'Translate'); ?>                              
                                        </span>
                                    </th>
                                <?php endif; ?>
                                <th>
                                    <span class="table-head">
                                        <span class="ui-icon ui-icon-gear"></span>
                                        <?php echo __d('system', 'Action'); ?>
                                    </span>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $_row = 1;
                            $defaultLanguage = Router::defaultLanguage();
                            $_queries = array('continue' => $this->request->here(false));
                            ?>
                            <?php foreach ($users as $user) : ?>
                                <tr class="table-row <?php echo $_row % 2 == 0 ? 'even' : 'odd'; ?>"> 
                                    <td class="table-col table-id">
                                        <?php echo $this->Form->input('id.', array('value' => $user['User']['id'], 'class' => 'row-id', 'type' => 'checkbox', 'hiddenField' => false, 'id' => false)); ?>
                                    </td>
                                    <?php if (isset($_displayFields['id'])): ?>
                                        <td class="table-col table-integer">
                                            <?php echo $user['User']['id']; ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['username'])): ?>
                                        <td class="table-col table-string">
                                            <?php echo String::truncate(strip_tags($user['User']['username'])); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['fullname'])): ?>
                                        <td class="table-col table-string">
                                            <?php echo String::truncate(strip_tags($user['User']['fullname'])); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['password'])): ?>
                                        <td class="table-col table-string">
                                            <?php echo String::truncate(strip_tags($user['User']['password'])); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['introduct'])): ?>
                                        <td class="table-col table-string">
                                            <?php echo String::truncate(strip_tags($user['User']['introduct'])); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['fulltext'])): ?>
                                        <td class="table-col table-text">
                                            <?php echo String::truncate(strip_tags($user['User']['fulltext'])); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['gender'])): ?>
                                        <td class="table-col table-boolean">
                                            <?php echo $this->Form->checkbox('gender', array('disabled' => true, 'hiddenField' => false, 'name' => '', 'id' => false, 'checked' => (bool) $user['User']['gender'])); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['birthday'])): ?>
                                        <td class="table-col table-date">
                                            <?php echo $this->Time->date($user['User']['birthday'], 'short'); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['email'])): ?>
                                        <td class="table-col table-string">
                                            <?php echo String::truncate(strip_tags($user['User']['email'])); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['phone'])): ?>
                                        <td class="table-col table-string">
                                            <?php echo String::truncate(strip_tags($user['User']['phone'])); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['enabled'])): ?>
                                        <td class="table-col table-boolean">
                                            <?php echo $this->Form->checkbox('enabled', array('disabled' => true, 'hiddenField' => false, 'name' => '', 'id' => false, 'checked' => (bool) $user['User']['enabled'])); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['role_id'])): ?>
                                        <td class="table-col table-string">
                                            <?php echo $user['Role'][$_modelMaps['Role']]; ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['created'])): ?>
                                        <td class="table-col table-datetime">
                                            <?php echo $this->Time->datetime($user['User']['created'], 'short'); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['updated'])): ?>
                                        <td class="table-col table-datetime">
                                            <?php echo $this->Time->datetime($user['User']['updated'], 'short'); ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['lft'])): ?>
                                        <td class="table-col table-integer">
                                            <?php echo $user['User']['lft']; ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['rght'])): ?>
                                        <td class="table-col table-integer">
                                            <?php echo $user['User']['rght']; ?>
                                        </td>
                                    <?php endif; ?>
                                    <?php if (isset($_translateMaps)): ?>
                                        <td class="table-col">
                                            <div class="table-translate">
                                                <?php
                                                foreach (Configure::read('Languages') as $_language) {
                                                    if ($_language['code'] === $defaultLanguage) {
                                                        continue;
                                                    }
                                                    echo $this->Html->link($this->Html->image('flag/' . $_language['code'] . '.png'), array('action' => 'translate', $user['User']['id'], $_language['code'], '?' => $_queries), array(
                                                        'class' => isset($_translateMaps[$user['User']['id']][$_language['locale']]) ? '' : 'ui-state-disabled', 'escape' => false, 'title' => $_language['name']));
                                                }
                                                ?>
                                            </div>
                                        </td>
                                    <?php endif; ?>
                                    <td class="table-col">
                                        <div class="table-actions">
                                            <?php echo $this->Html->link('Edit', array('action' => 'edit', $user['User']['id'], '?' => $_queries), array('title' => __d('system', 'Edit this item'), 'class' => 'ui-icon ui-icon-pencil')); ?>
                                            <?php echo $this->Html->link('Delete', array('action' => 'delete', '?' => array_merge($_queries, array('keys' => array($user['User']['id'])))), array('title' => __d('system', 'Delete this item'), 'class' => 'ui-icon ui-icon-trash'), __d('system', 'Are you sure to delete #%s ?', $user['User']['id'])); ?>

                                            <?php echo $this->Html->link('Move up', array('action' => 'move', $user['User']['id'], 'up', '?' => $_queries), array('title' => __d('system', 'Move up this item'), 'class' => 'ui-icon ui-icon-arrowthick-1-n')); ?>
                                            <?php echo $this->Html->link('Move down', array('action' => 'move', $user['User']['id'], 'down', '?' => $_queries), array('title' => __d('system', 'Move down this item'), 'class' => 'ui-icon ui-icon-arrowthick-1-s')); ?>
                                            <?php
                                            if ($_toParent) {
                                                echo $this->Html->link('Children', array('ext' => false, '?' => array_merge($this->request->query, array('_parent_id' => $user['User']['id']))), array('title' => __d('system', 'Management children of this item'), 'class' => 'ui-icon ui-icon-folder-collapsed'));
                                            }
                                            ?>

                                        </div>
                                    </td> 
                                </tr>
                                <?php $_row++; ?>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="table-toolbar ui-corner-bottom clearfix">
                <div class="table-info">
                    <?php echo $this->Paginator->counter(__d('system', 'Showing %start% to %end% of %count% entries')); ?>
                </div>
                <div class="table-paginate clearfix">
                    <?php echo $this->Paginator->first(__d('system', 'Fisrt')); ?>
                    <?php echo $this->Paginator->prev(__d('system', 'Prev'), array(), null, array('class' => 'disabled')); ?>
                    <?php echo $this->Paginator->numbers(array('separator' => '')); ?>
                    <?php echo $this->Paginator->next(__d('system', 'Next'), array(), null, array('class' => 'disabled')); ?>
                    <?php echo $this->Paginator->last(__d('system', 'Last')); ?>
                </div>
            </div>
        </div>
        <?php
        echo $this->Form->hidden('task', array('id' => 'task', 'value' => ''));
        echo $this->Form->end();
        ?>
    </div>
    <!-- /Table -->
</div>